import datetime
import time

#获取时间戳
time_1=time.time()
#时间戳-->datetime.datetime
time_dd=datetime.datetime.fromtimestamp(time_1, tz=None)
#datetime.datetime-->str
time_str=time_dd.strftime("%Y/%m/%d %H:%M:%S")
#str-->datetime.datetime
time_datetime=datetime.datetime.strptime(time_str, "%Y/%m/%d %H:%M:%S")
#datetime.datetime-->时间戳
time_stamp=time_datetime.timestamp()

print("获取时间戳:", end="  ")
print(time_1)
print("时间戳-->datetime.datetime:", end="  ")
print(time_dd)
print("datetime.datetime-->str:", end="  ")
print(time_str)
print("str-->datetime.datetime:", end="  ")
print(time_datetime)
print("datetime.datetime-->时间戳:", end="  ")
print(time_stamp)

print("----------------------------------")
# 如果传入的是`-1` , 输出就是字符串日期2020-01-02.
def get_date(day_delta):
    now = datetime.datetime.now(tz=None)
    if day_delta==-1:
        print(now.strftime("%Y-%m-%d"))


get_date(-1)